package server;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

import query.AbstractQuery;

/**
 * ServerWorker
 * @author Safran/Azubi
 *
 */
public class ServerWorker implements Runnable {
	
	protected Socket clientSocket = null;
	protected String serverText = null;

	/**
	 * Server Worder Erstellen
	 * @param clientSocket
	 * @param serverText
	 */
	public ServerWorker(Socket clientSocket, String serverText) {
		this.clientSocket = clientSocket;
		this.serverText = serverText;
	}

	/* (non-Javadoc)
	 * @see java.lang.Runnable#run()
	 */
	public void run() {
		try {
			//IOstream erstellen
			ObjectInputStream serverInputStream = new ObjectInputStream(clientSocket.getInputStream());
			ObjectOutputStream serverOutputStream = new ObjectOutputStream(clientSocket.getOutputStream());
			AbstractQuery q = (AbstractQuery) serverInputStream.readObject();
			q.setServerOutputStream(serverOutputStream);
			q.doAction();
			serverInputStream.close();
			serverOutputStream.close();
		} catch (Exception e) {
			e.printStackTrace();		
		}
	}
}
